Add --enable-embed=static support on Windows#22166
Conversation
Seems very much like a concern for here too, in the same breath. There's no reason to support downstream build adjustments in source code here, especially because it's impossible to test them. The entire |
|
I'm sorry, I didn't 100% understand your feedback, are you asking for changes? |
|
Yes. There shouldn't be a |
|
Very good feedback, I'll try and get it changed. Thank you |
f1c729c to
9eb3202
Compare
shivammathur
left a comment
There was a problem hiding this comment.
Thanks for working on this. I think this needs a bit more work before it can land.
sapi/embed/config.w32should handle/documentyes,no,shared, andstaticsimilarly toconfig.m4, including theARG_ENABLEhelp text.- We should expose a public static-embed marker, something like
PHP_EMBED_STATIC, through the installed embed headers so external embed consumers do not get PHP/Zend/SAPI/TSRM APIs expanded asdllimport. - This likely also needs some
confutils.jschanges to preserve the generated-file dependency and include the needed static link inputs, plusmkdist.php/packaging changes sophp<N>embed.libis shipped as a devel library underlib.
Could you also test this end-to-end by building with --enable-embed=static and linking a minimal external embed program against the installed headers/libs, and checking that the resulting binary does not depend on php<N>.dll.
Addresses shivammathur's review on PR php#22166: * sapi/embed/config.w32: document ARG_ENABLE TYPE values (shared|static) to match config.m4's help string. Annotate the static branch with a pointer to the confutils.js Makefile rule. * sapi/embed/php_embed.h: expose a public PHP_EMBED_STATIC marker. External consumers linking against a statically built php<N>embed.lib define PHP_EMBED_STATIC before including this header, which suppresses __declspec(dllimport) decoration on PHP/Zend/SAPI/TSRM APIs so they resolve directly against the static lib (matches what php-src uses internally when compiling its own TUs). * win32/build/mkdist.php: route .lib SAPI targets (e.g. the static php<N>embed.lib) to dist_dir/dev/ instead of dist_dir/, keeping the runtime tree free of devel libraries. * NEWS: extend the embed-static entry to mention the public marker and the dist /dev/ routing.
|
I have this building fine in a fork but still haven't confirmed everything end to end due to other issues in my build pipeline, I am still working on this and have not forgotten. |
PHP's Unix build already documents and accepts --enable-embed=static (see sapi/embed/config.m4) for building php<N>embed as a static library with no DLL at runtime. The Windows config.w32 ignored the static value, leaving php<N>embed.lib as a thin wrapper that still depended on php<N>.dll at runtime. When --enable-embed=static is passed on Windows: * win32/build/confutils.js generates a Makefile rule for php<N>embed .lib that links in PHP core (PHP_GLOBAL_OBJS), statically built extensions (STATIC_EXT_OBJS + STATIC_EXT_LIBS), the embed SAPI objects, and ASM_OBJS in place of the import lib (BUILD_DIR/PHPLIB). The resulting php<N>embed.lib is a self-contained static library with no runtime DLL dependency. * sapi/embed/config.w32 adds /D PHP_EXPORTS /D LIBZEND_EXPORTS /D SAPI_EXPORTS /D TSRM_EXPORTS to CFLAGS_EMBED so php_embed.c references PHP/Zend/SAPI/TSRM symbols directly instead of through __declspec(dllimport) thunks (which would produce LNK2019 with no DLL to import from), and defines PHP_EMBED_STATIC as a gate. * sapi/embed/php_embed.c skips its ZEND_TSRMLS_CACHE_DEFINE() when PHP_EMBED_STATIC is set. In static mode zend.c is in the same link unit and already defines _tsrm_ls_cache; the duplicate from php_embed.c produced LNK4006 and a corrupt binary.
9eb3202 to
ea83225
Compare
|
Following up on my earlier comment — end-to-end validation is done. Build: PHP-8.5 (this branch, reports Link + run: minimal host program, nothing but the static lib: PHP_EMBED_START_BLOCK(argc, argv)
zend_eval_string("echo 'EMBEDOK ' . PHP_VERSION . ' zts=' . (ZEND_THREAD_SAFE ? '1' : '0') . ' sapi=' . php_sapi_name();", NULL, "smoke");
PHP_EMBED_END_BLOCK()Output: The NTS variant of this same change has additionally been shipping in production since May as the Windows build path for ePHPm (Rust server embedding PHP statically), so both TS and NTS configurations are exercised. CI is green on the rebased head, including |
Summary
Unix already supports
--enable-embed=static(seesapi/embed/config.m4); the Windowsconfig.w32ignored thestaticvalue andphp_embed.cgot compiled as a DLL consumer regardless. Result: linking embed withoutphp<N>.dllfails withLNK2019on every PHP/Zend symbol referenced fromphp_embed.c, and (under ZTS)LNK4006on_tsrm_ls_cachedue to a duplicate definition betweenzend.candphp_embed.c.When
--enable-embed=staticis passed on Windows:CFLAGS_EMBEDgets/D PHP_EXPORTS /D LIBZEND_EXPORTS /D SAPI_EXPORTS /D TSRM_EXPORTSsophp_embed.creferences core symbols directly instead of through__declspec(dllimport)thunks.php_embed.c'sZEND_TSRMLS_CACHE_DEFINE()is skipped (gated on newPHP_EMBED_STATIC);zend.cprovides the canonical definition.This patches only the source-side adjustments. Producing a fat static lib (composition of
php<N>embed.lib) is a separate Makefile concern handled by downstream build tools.